package com.zkdcloud.aspectInterceptor.validatie;

import com.xdja.interceptor.exception.InvokeException;
import com.xdja.interceptor.util.ValidateUtils;
import com.zkdcloud.domain.Admin;
import com.zkdcloud.domain.Category;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;

import static com.zkdcloud.constant.Constants.HTTP_CONSTANTS.REQUEST_ADMIN;

/**
 * 分类controller validate
 *
 * @author zk
 * @since 2018/5/2
 */
@Component
public class CategoryControllerValidate {
    /**
     * static logger
     */
    private static Logger logger = LoggerFactory.getLogger(CategoryControllerValidate.class);

    /**
     * 添加分类
     *
     * @param category category
     */
    public void add(Category category, HttpServletRequest request) throws InvokeException {
        ValidateUtils.assertCondition(!StringUtils.isEmpty(category.getName()),"分类名不能为空");
        ValidateUtils.assertCondition(!StringUtils.isEmpty(category.getIconUrl()),"分类url不能为空");

        Admin admin = (Admin) request.getAttribute(REQUEST_ADMIN);
        category.setBusinessId(admin.getBusinessId());
    }
}
